Análisis exploratorio de la incidencia de cáncer en población femenina costarricense para el periodo 2009-2014
El cáncer es un conjunto de enfermedades con alta prevalencia en la
población y constituye una de las principales causas de muerte en Costa
Rica y a nivel mundial. Es de especial relevancia en poblaciones
envejecidas o en proceso de envejecimiento debido a que el riesgo de
padecer cáncer aumenta con la edad. Asimismo, suele afectar con mayor
severidad a países en vía de desarrollo y sectores socioeconómicamente
desfavorecidos, ya que estos no suelen contar con recursos para acceder
a un diagnostico oportuno y un tratamiento adecuado. Debido a lo
anterior, es de especial importancia vigilar y comprender el
comportamiento epidemiológico del cáncer en Costa Rica y en sus
diferentes unidades territoriales. Para esto, se analizó datos de
incidencia de cáncer en Costa Rica para población femenina entre el
periodo del 2009-2014, estos datos incluyen información de incidencia
por tipo de cáncer, edad, cantón y provincia.
Se decidió trabajar en población femenina con el fin de acotar el
análisis, sin embargo, el mismo procedimiento y código se puede usar
para analizar a la población masculina. De igual forma, a futuro se
recomienda realizar un análisis similar para mortalidad y sobrevida.
Objetivo General: Caracterizar la situación
epidemiología del cáncer en población femenina costarricense para el
periodo comprendido entre el 2009 – 2014.
Objetivos Específicos:
(1) Determinar posibles tendencias en la incidencia de los
principales tipos de cáncer durante el periodo de estudio.
(2) Evaluar el efecto de la edad sobre la incidencia.
(3) Resumir los datos de incidencia de manera tal que sean
fácilmente interpretables.
(4) Caracterizar la incidencia para las diferentes provincias y
cantones.
(5) Agrupar los tipos de cáncer según la incidencia por
edad.
(6) Agrupar los cantones según la incidencia de los canceres más
frecuentes.
Recolección de datos:
Los datos corresponden a datos públicos del Ministerio de Salud. Los
mismos son tomados del Registro Nacional de Tumores (RNT). El RNT fue
creado mediante decreto ejecutivo en 1976 y desde entonces almacena la
información de incidencia y prevalencia del cáncer en Costa Rica. La
notificación de cualquier tipo de cáncer por parte del personal medico
es obligatoria desde la creación del RNT, mientras desde 1980 es
obligatoria la notificación por parte de cualquier laboratorio de
patología. Para el 2012, el 88,08 % de los diagnósticos correspondían a
histología, mientras que el resto corresponden a cirugía, investigación
clínica y diagnostico únicamente clínico.
Lectura de datos
Creamos una función que facilita la lectura de los datos y el cambio de los nombres de las columnas.
leer_incidencia <- function(direccion, year){
datos <- read.table(direccion, header = TRUE, sep = "\t", quote = "\"",
dec = ",", fill = TRUE)
colnames(datos)[1:20] <- c("id", "localizacion", "n_total", "incidencia_total",
"0-5", "5-10", "10-15", "15-20", "20-25", "25-30",
"30-35", "35-40", "40-45", "45-50", "50-55", "55-60",
"60-65", "65-70", "70-75", "75+")
datos[1,1] <- "0"
datos$year <- year
return(datos)
}Lectura de los datos que abarcan el periodo entre el 2009 y 2014.
mujeres2009 <- leer_incidencia("2009_mujeres_incidencia.txt", 2009)
mujeres2010 <- leer_incidencia("2010_mujeres_incidencia.txt", 2010)
mujeres2011 <- leer_incidencia("2011_mujeres_incidencia.txt", 2011)
mujeres2012 <- leer_incidencia("2012_mujeres_incidencia.txt", 2012)
mujeres2013 <- leer_incidencia("2013_mujeres_incidencia.txt", 2013)
mujeres2014 <- leer_incidencia("2014_mujeres_incidencia.txt", 2014)
#Unimos todos los data frame en un uno solo.
mujeresIncidencia <- rbind(mujeres2009, mujeres2010, mujeres2011,
mujeres2012, mujeres2013, mujeres2014)Generamos una tabla interactiva con filtros.
library(DT)
datatable(mujeresIncidencia, class = 'cell-border stripe', options = list(pageLength = 5),
filter = list(position = 'bottom', clear = TRUE ))Incidencia de cáncer en mujeres costarricenses para el 2009 - 2014
Convertimos a filas los valores de incidencia que estaban agrupados en distintas columnas según el rango de edad. Este formato “alargado” favorece la graficación.
library(tidyr)
datosLargo <- pivot_longer(mujeresIncidencia, cols=5:20, names_to = "Edad", values_to = "Incidencia")
tail(datosLargo)## # A tibble: 6 x 7
## id localizacion n_total incidencia_total year Edad Incide~1
## <chr> <chr> <int> <dbl> <dbl> <chr> <dbl>
## 1 C80 SITIO PRIMARIO DESCONOCIDO 82 3.47 2014 50-55 2.87
## 2 C80 SITIO PRIMARIO DESCONOCIDO 82 3.47 2014 55-60 9.58
## 3 C80 SITIO PRIMARIO DESCONOCIDO 82 3.47 2014 60-65 6.94
## 4 C80 SITIO PRIMARIO DESCONOCIDO 82 3.47 2014 65-70 21.5
## 5 C80 SITIO PRIMARIO DESCONOCIDO 82 3.47 2014 70-75 22.7
## 6 C80 SITIO PRIMARIO DESCONOCIDO 82 3.47 2014 75+ 25.1
## # ... with abbreviated variable name 1: Incidencia
Gráfico de canceres con mayor frecuencia
Seleccionamos los canceres más frecuentes para el año 2009 y 2014.
#Data frame que solo contiene los datos del 2009
largo2009 <- datosLargo[datosLargo$year==2009,]
#Eliminamos los datos que corresponden a la suma total de todos los canceres
orden2009 <- largo2009[(largo2009$localizacion != "TOTAL"),]
#Ordenamos en orden decreciente los datos según la incidencia total
orden2009 <- orden2009[order(orden2009$incidencia_total, decreasing = TRUE),]
#Seleccionamos los 10 canceres más frecuentes para el 2009
index2009 <- unique(orden2009$localizacion)[1:10]
#Realizamos el mismo procedimiento para el 2014
largo2014 <- datosLargo[datosLargo$year==2014,]
orden2014 <- largo2014[(largo2014$localizacion != "TOTAL"),]
orden2014 <- orden2014[order(orden2014$incidencia_total, decreasing = TRUE),]
index2014 <- unique(orden2014$localizacion)[1:10]
#Concatenamos los canceres y usamos unique() para no tener valores repetidos
#De esta forma tenemos en el objeto "frecuentes" los canceres más frecuentes del
#2009 y 2014
frecuentes <- unique(c(index2009, index2014))
frecuentes## [1] "PIEL"
## [2] "MAMA"
## [3] "CUELLO UTERINO"
## [4] "GLANDULA TIROIDES"
## [5] "ESTOMAGO"
## [6] "COLON"
## [7] "SITIO PRIMARIO DESCONOCIDO"
## [8] "CUERPO UTERINO"
## [9] "SISTEMAS HEMATOPOYETICO Y RETICULOENDOTELIAL"
## [10] "GANGLIOS LINFATICOS"
## [11] "OVARIO"
## [12] "BRONQUIOS Y PULMON"
library(ggplot2)
library(plotly)
incidenciaFrecuentes <- datosLargo[datosLargo$localizacion %in% frecuentes,]
incidenciaFrecuentes$localizacion <- as.factor(incidenciaFrecuentes$localizacion)
#Cambiamos el nombre por minúscula y nombres más cortos
levels(incidenciaFrecuentes$localizacion) <- c("Bronquios y pulmón",
"Colon", "Cuello uterino",
"Cuerpo Uterino", "Estomago",
"Ganglios linfáticos",
"glándula tiroides", "Mama",
"Ovario", "Piel", "Hematopoyético y reticuloendotelial",
"Sitio primario desconocido")
p1 <- incidenciaFrecuentes |> ggplot(aes(x = year, y = incidencia_total, colour = localizacion)) +
geom_line() + geom_point(size = 2) + theme_classic()
p1 <- p1 + labs(y = "Incidencia cada 100.000 habitantes",
x = "Año",
colour = "Localización")
#Usamos la librería ggploty para generar un gráfico interactivo.
ggplotly(p1)Tabla de canceres más frecuentes según el año.
Transformamos los datos a una formato “a lo ancho” que favorece la visualización de los cambios en la incidencia según el año.
#Eliminamos columna de edad e incidencia por edad.
datosAncho <- unique(datosLargo[, - c(6,7)])
datosAncho <- pivot_wider(datosAncho,id_cols=localizacion, names_from = year, values_from = incidencia_total)
#Ordenamos los datos en forma descendente según la incidencia del 2014
datosAncho <- datosAncho[order(datosAncho$`2014`, decreasing = TRUE),]
library(DT)
datatable(datosAncho, class = 'cell-border stripe', options = list(pageLength = 5))Incidencia según el rango de edad para los años 2009 y 2014.
#Barplot
totalEdad <- datosLargo[datosLargo$localizacion == "TOTAL",]
#Convertimos edad a factor
totalEdad$Edad <- as.factor(totalEdad$Edad)
#Cambiamos el orden de los factores
totalEdad$Edad <- factor(totalEdad$Edad ,levels(totalEdad$Edad)[c(1, 10, 2:9, 11:16)])Vamos a crear un gráfico de barras usando únicamente los datos de los años 2009 y 2014. Esto con el fin de observar posibles cambios de tendencia para el periodo analizado.
#Barplot
totalEdad <- datosLargo[datosLargo$localizacion == "TOTAL",]
#Convertimos edad a factor
totalEdad$Edad <- as.factor(totalEdad$Edad)
#Cambiamos el orden de los factores
totalEdad$Edad <- factor(totalEdad$Edad ,levels(totalEdad$Edad)[c(1, 10, 2:9, 11:16)])
#Seleccionamos los datos del 2009 y 2014
totalEdad_09_14 <- totalEdad[totalEdad$year == 2009 |
totalEdad$year == 2014,]
#Seleccionamos los datos del 2009 y 2014
totalEdad_09_14 <- totalEdad[totalEdad$year == 2009 |
totalEdad$year == 2014,]
#Transformanos la variable año a factor
totalEdad_09_14$year <- as.factor(totalEdad_09_14$year)
#Graficación
ggplot(totalEdad_09_14, aes(x = Edad, y = Incidencia, fill = year)) +
geom_bar(stat="identity", color = "black",
position = "dodge", width = 0.8) +
labs(y = "Incidencia cada 100.000 habitantes",
x = "Rango de edad",
fill = "Año") + theme_classic()Incidencia según el rango de edad para los canceres más frecuentes
Vamos a generar un heatmap con los 20 canceres más frecuentes para el año 2014
#Ordenamos de forma decresciente según la incidencia total
matrizIncidencia <- mujeresIncidencia[order(mujeresIncidencia$incidencia_total, decreasing = TRUE), ]
#Seleccionamos los datos que pertenecen al 2014 y que no son un total.
#Eliminamos las columnas id, localización n_total, incidencia_total y year.
matrizIncidencia <- matrizIncidencia[matrizIncidencia$year == 2014 &
matrizIncidencia$localizacion != "TOTAL",
c(-1, -3, -4, -21)]
incidenciaCluster <- matrizIncidencia #Lo guardamos para más adelante
#Le asignamos nombre a las filas
rownames(matrizIncidencia) <- matrizIncidencia$localizacion
#Eliminamos columna localización
matrizIncidencia <- matrizIncidencia[, -1]
datosClusterIncidencia <- matrizIncidencia #Lo guardamos para el k-means
#Transformamos el dataframe a matriz
matrizIncidencia <- as.matrix(matrizIncidencia)
#Generamos el gráfico
heatmap(matrizIncidencia[1:20,], xlab="Rango de edad")Cambio en la incidencia entre los años 2009 y 2014
#Seleccionamos los datos del 2009 y eliminamos columnas de edad e incidencia por edad.
#Eliminamos los datos de localización que corresponden al total.
#Eliminamos las filas repetidas
df2009 <- unique(datosLargo[datosLargo$year == 2009 &
datosLargo$localizacion != "TOTAL",
- c(6,7)])
#Realizamos lo mismo para el 2014
df2014 <- unique(datosLargo[datosLargo$year == 2014 &
datosLargo$localizacion != "TOTAL",
- c(6,7)])
head(df2014)## # A tibble: 6 x 5
## id localizacion n_total incidencia_total year
## <chr> <chr> <int> <dbl> <dbl>
## 1 C00 LABIO 2 0.08 2014
## 2 C01 BASE LENGUA 3 0.13 2014
## 3 C02 OTRAS PARTES Y LAS NO ESPECIF. LENGUA 14 0.59 2014
## 4 C03 ENCIA 0 0 2014
## 5 C04 PISO DE LA BOCA 1 0.04 2014
## 6 C05 PALADAR 4 0.17 2014
Debemos verificar que los set de datos del 2014 y 2015 tengan el mismo formato, esto nos asegura que podemos realizar operar entre ellos.
#Verificamos que el orden de la variable localización sea la misma para el 2009 y 2014
#Primero debemos eliminar la fila 35 que solo está en 2014 y no en 2009
df2014[35,]## # A tibble: 1 x 5
## id localizacion n_total incid~1 year
## <chr> <chr> <int> <dbl> <dbl>
## 1 C39 OTROS SITIOS Y LOS MAL DEF. DEL SIST. RESP. Y LOS~ 0 0 2014
## # ... with abbreviated variable name 1: incidencia_total
df2014 <- df2014[-35,]
#Verificamos que ambos vectores de localización sean iguales
#El false en posición 55 se debe a una diferencia en una ñ (RIÑON != RI?ON),
df2009$localizacion == df2014$localizacion## [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [13] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [25] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [37] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [49] TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE
## [61] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
Calculamos el cambio porcentual entre el 2009 y 2014, para esto
usamos la formula:
Δ% = ( ( valor final – valor inicial ) / valor inicial ) x
100
#Cambio porcentual
cambio = ((df2014$incidencia_total - df2009$incidencia_total)/df2009$incidencia_total)*100
#Cambio en la cantidad
cambioCantidad = df2014$n_total - df2009$n_total
#Generamos un dataframe
dfCambios <- data.frame(localizacion = df2009$localizacion,
Cambio_porcentual = cambio,
Cambio_cantidad = cambioCantidad)
#Ordenamos de forma descendiente según el cambio en la cantidad entre 2009 y 2014
dfCambios <- dfCambios[order(dfCambios$Cambio_cantidad, decreasing = TRUE),]
#Generamos la tabla con los datos
datatable(dfCambios, class = 'cell-border stripe', options = list(pageLength = 5))Agrupamiento de los tipos de cáncer según la incidencia por edad
Vamos a emplear el algoritmo de k-means para agrupar los canceres en distintos “clusters”. Primero veamos los datos que tenemos hasta el momento.
head(datosClusterIncidencia)## 0-5 5-10 10-15 15-20 20-25 25-30 30-35 35-40 40-45 45-50
## MAMA 0.00 0.00 0.00 0.00 1.42 5.04 11.79 38.06 65.75 125.16
## PIEL 0.00 0.56 0.53 0.50 0.95 2.75 8.71 10.54 34.85 61.58
## CUELLO UTERINO 0.00 0.00 0.00 3.98 17.55 35.25 63.03 60.89 59.83 46.18
## GLANDULA TIROIDES 0.56 0.00 1.07 2.99 10.91 17.40 40.99 37.47 44.71 65.59
## ESTOMAGO 0.00 0.00 0.00 0.00 0.00 2.29 4.10 6.44 7.23 11.38
## COLON 0.00 0.00 0.53 0.50 0.00 1.83 4.10 5.27 5.26 12.05
## 50-55 55-60 60-65 65-70 70-75 75+
## MAMA 125.76 179.38 217.52 185.57 229.29 196.75
## PIEL 72.58 124.52 158.51 222.02 347.34 600.80
## CUELLO UTERINO 40.24 32.22 46.28 18.23 34.05 33.01
## GLANDULA TIROIDES 91.27 60.95 48.59 28.17 45.40 19.81
## ESTOMAGO 15.81 26.99 30.08 48.05 90.81 112.24
## COLON 15.09 25.25 35.87 43.08 77.19 118.84
Se debe escalar los datos para tener un centroide en 0.
datosClusterIncidencia <- scale(datosClusterIncidencia)Primero debemos calcular el número de clusters, vamos a usar tres índices distintos.
library(factoextra)
fviz_nbclust(datosClusterIncidencia, kmeans, method = "wss")fviz_nbclust(datosClusterIncidencia, kmeans, method = "silhouette")fviz_nbclust(datosClusterIncidencia, kmeans, method = "gap_stat")Como no obtuvimos un resultado definitivo, vamos a usar la librería NbClust para calcular 30 índices distintos y decidir con base en el resultado de la mayoría.
library(NbClust)
resnumclust<-NbClust(datosClusterIncidencia, distance = "euclidean", min.nc=2, max.nc=10, method = "kmeans", index = "alllong")## *** : The Hubert index is a graphical method of determining the number of clusters.
## In the plot of Hubert index, we seek a significant knee that corresponds to a
## significant increase of the value of the measure i.e the significant peak in Hubert
## index second differences plot.
##
## *** : The D index is a graphical method of determining the number of clusters.
## In the plot of D index, we seek a significant knee (the significant peak in Dindex
## second differences plot) that corresponds to a significant increase of the value of
## the measure.
##
## *******************************************************************
## * Among all indices:
## * 6 proposed 2 as the best number of clusters
## * 3 proposed 3 as the best number of clusters
## * 6 proposed 4 as the best number of clusters
## * 4 proposed 5 as the best number of clusters
## * 1 proposed 7 as the best number of clusters
## * 4 proposed 8 as the best number of clusters
## * 2 proposed 9 as the best number of clusters
## * 2 proposed 10 as the best number of clusters
##
## ***** Conclusion *****
##
## * According to the majority rule, the best number of clusters is 2
##
##
## *******************************************************************
fviz_nbclust(resnumclust)## Among all indices:
## ===================
## * 2 proposed 0 as the best number of clusters
## * 6 proposed 2 as the best number of clusters
## * 3 proposed 3 as the best number of clusters
## * 6 proposed 4 as the best number of clusters
## * 4 proposed 5 as the best number of clusters
## * 1 proposed 7 as the best number of clusters
## * 4 proposed 8 as the best number of clusters
## * 2 proposed 9 as the best number of clusters
## * 2 proposed 10 as the best number of clusters
##
## Conclusion
## =========================
## * According to the majority rule, the best number of clusters is 2 .
Con base en lo anterior, debemos usar 2 clusters.
K-Means (k = 2)
k2 <- kmeans(datosClusterIncidencia, centers = 2, nstart = 50)
k2## K-means clustering with 2 clusters of sizes 4, 66
##
## Cluster means:
## 0-5 5-10 10-15 15-20 20-25 25-30
## 1 -0.133838321 0.024351886 0.62116525 1.7319783 2.8820834 2.9722563
## 2 0.008111413 -0.001475872 -0.03764638 -0.1049684 -0.1746717 -0.1801367
## 30-35 35-40 40-45 45-50 50-55 55-60 60-65
## 1 3.2175235 3.5613861 3.8669206 3.6719950 3.6800702 3.3581276 3.2453804
## 2 -0.1950014 -0.2158416 -0.2343588 -0.2225452 -0.2230346 -0.2035229 -0.1966897
## 65-70 70-75 75+
## 1 2.8881856 2.902763 2.5047147
## 2 -0.1750416 -0.175925 -0.1518009
##
## Clustering vector:
## MAMA
## 1
## PIEL
## 1
## CUELLO UTERINO
## 1
## GLANDULA TIROIDES
## 1
## ESTOMAGO
## 2
## COLON
## 2
## CUERPO UTERINO
## 2
## GANGLIOS LINFATICOS
## 2
## OVARIO
## 2
## BRONQUIOS Y PULMON
## 2
## SISTEMAS HEMATOPOYETICO Y RETICULOENDOTELIAL
## 2
## RECTO
## 2
## SITIO PRIMARIO DESCONOCIDO
## 2
## PANCREAS
## 2
## RI?ON
## 2
## HIGADO Y CONDUCTOS BILIARES INTRAHEPATICOS
## 2
## TEJIDO CONJUNTIVO, SUBCUTANEO Y DE OTROS TEJIDOS BLANDOS
## 2
## UNION RECTOSIGMOIDEA
## 2
## VEJIGA URINARIA
## 2
## ENCEFALO
## 2
## VULVA
## 2
## VESICULA BILIAR
## 2
## VAGINA
## 2
## UTERO, SAI
## 2
## ANO Y CONDUCTO ANAL
## 2
## OTRAS PARTES Y LAS NO ESPECIF. DE LAS VIAS BILIARES
## 2
## OTRAS PARTES Y LAS NO ESPECIF. LENGUA
## 2
## AMIGDALA
## 2
## HUESOS, ARTICULACIONES Y CARTILAGOS ARTICULARES DE OTROS SITIOS Y DE LOS NO ESPECIF.
## 2
## PERITONEO Y RETROPERITONEO
## 2
## OJO Y ANEXOS
## 2
## GLANDULA PAROTIDA
## 2
## INTESTINO DELGADO
## 2
## HUESOS, ARTICULACIONES Y CARTILAGOS ARTICULARES DE LOS MIEMBROS
## 2
## OTRAS GLANDULAS SALIVALES MAYORES Y LAS NO ESPECIF.
## 2
## CORAZON, MEDIASTINO Y PLEURA
## 2
## OTRAS PARTES Y LAS NO ESPECIF. BOCA
## 2
## NASOFARINGE
## 2
## ESOFAGO
## 2
## LARINGE
## 2
## OTRAS GLANDULAS ENDOCRINAS Y ESTRUCTURAS AFINES
## 2
## SITIOS MAL DEFINIDOS Y OTROS
## 2
## PALADAR
## 2
## CAVIDAD NASAL Y OIDO MEDIO
## 2
## BASE LENGUA
## 2
## HIPOFARINGE
## 2
## LABIO
## 2
## OROFARINGE
## 2
## OTROS SITIOS Y LOS MAL DEF. DE LOS ORGANOS DIGESTIVOS
## 2
## SENOS PARANASALES
## 2
## OTROS ORGANOS GENITALES FEMENINOS Y LOS NO ESPECIF.
## 2
## PELVIS RENAL
## 2
## MENINGES
## 2
## MEDULA ESPINAL, NERVIOS CRANEALES Y DE OTRAS PARTES DEL SISTEMA NERVIOSO CENTRAL
## 2
## GLANDULA SUPRARRENAL (ADRENAL)
## 2
## PISO DE LA BOCA
## 2
## TRAQUEA
## 2
## OTROS ORGANOS URINARIOS Y LOS NO ESPECIF.
## 2
## ENCIA
## 2
## SENO PIRIFORME
## 2
## OTROS SITIOS Y LOS MAL DEF. DEL LABIO, CAVIDAD BUCAL Y FARINGE
## 2
## TIMO
## 2
## OTROS SITIOS Y LOS MAL DEF. DEL SIST. RESP. Y LOS ORG. INTRAT.
## 2
## NERVIOS PERIFERICOS Y SISTEMA NERVIOSO AUTONOMO
## 2
## PLACENTA
## 2
## PENE
## 2
## GLANDULA PROSTATICA
## 2
## TESTICULOS
## 2
## OTROS ORGANOS GENITALES MASCULINOS Y LOS NO ESPECIF.
## 2
## URETER
## 2
##
## Within cluster sum of squares by cluster:
## [1] 271.1853 279.5557
## (between_SS / total_SS = 50.1 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault"
Procedemos a graficar el resultado.
fviz_cluster(k2, data = datosClusterIncidencia, ellipse.type = "euclid",repel = TRUE,star.plot = TRUE)K-Means (k = 5)
k5 <- kmeans(datosClusterIncidencia, centers = 5, nstart = 50)
k5## K-means clustering with 5 clusters of sizes 5, 2, 60, 1, 2
##
## Cluster means:
## 0-5 5-10 10-15 15-20 20-25 25-30
## 1 0.3866440 1.2968795 1.1574230 2.09129833 0.1783610 0.08747564
## 2 -0.3073324 0.3018501 0.3195203 -0.07019275 0.2363660 0.58529931
## 3 -0.1338383 -0.2161466 -0.2528604 -0.32088115 -0.2125305 -0.20950168
## 4 6.6324323 6.3869900 6.8998499 1.86846420 0.3316889 0.24369735
## 5 0.0396558 -0.2531463 0.9228102 3.53414933 5.5278009 5.35921330
## 30-35 35-40 40-45 45-50 50-55 55-60
## 1 -0.1193399 -0.03610941 -0.17344049 -0.03928692 -0.1433901 -0.09113406
## 2 0.9032437 2.26043133 3.78685956 4.67031870 4.4900113 5.30846357
## 3 -0.2016181 -0.23177552 -0.24365310 -0.23944879 -0.2315791 -0.21905862
## 4 -0.1763102 -0.15846609 0.01870607 -0.12461782 -0.1085831 0.16667717
## 5 5.5318033 4.86234088 3.94698170 2.67367134 2.8701290 1.40779164
## 60-65 65-70 70-75 75+
## 1 -0.1231566 -0.05542237 -0.1481637 -0.138580000
## 2 5.3737476 5.46308512 5.3502589 4.934334257
## 3 -0.2036958 -0.18920869 -0.1787012 -0.155535866
## 4 -0.1439891 0.07689064 -0.1481637 0.006192999
## 5 1.1170132 0.31328608 0.4552677 0.075095237
##
## Clustering vector:
## MAMA
## 2
## PIEL
## 2
## CUELLO UTERINO
## 5
## GLANDULA TIROIDES
## 5
## ESTOMAGO
## 3
## COLON
## 3
## CUERPO UTERINO
## 3
## GANGLIOS LINFATICOS
## 1
## OVARIO
## 1
## BRONQUIOS Y PULMON
## 3
## SISTEMAS HEMATOPOYETICO Y RETICULOENDOTELIAL
## 4
## RECTO
## 3
## SITIO PRIMARIO DESCONOCIDO
## 3
## PANCREAS
## 3
## RI?ON
## 3
## HIGADO Y CONDUCTOS BILIARES INTRAHEPATICOS
## 3
## TEJIDO CONJUNTIVO, SUBCUTANEO Y DE OTROS TEJIDOS BLANDOS
## 1
## UNION RECTOSIGMOIDEA
## 3
## VEJIGA URINARIA
## 3
## ENCEFALO
## 1
## VULVA
## 3
## VESICULA BILIAR
## 3
## VAGINA
## 3
## UTERO, SAI
## 3
## ANO Y CONDUCTO ANAL
## 3
## OTRAS PARTES Y LAS NO ESPECIF. DE LAS VIAS BILIARES
## 3
## OTRAS PARTES Y LAS NO ESPECIF. LENGUA
## 3
## AMIGDALA
## 3
## HUESOS, ARTICULACIONES Y CARTILAGOS ARTICULARES DE OTROS SITIOS Y DE LOS NO ESPECIF.
## 3
## PERITONEO Y RETROPERITONEO
## 3
## OJO Y ANEXOS
## 3
## GLANDULA PAROTIDA
## 3
## INTESTINO DELGADO
## 3
## HUESOS, ARTICULACIONES Y CARTILAGOS ARTICULARES DE LOS MIEMBROS
## 1
## OTRAS GLANDULAS SALIVALES MAYORES Y LAS NO ESPECIF.
## 3
## CORAZON, MEDIASTINO Y PLEURA
## 3
## OTRAS PARTES Y LAS NO ESPECIF. BOCA
## 3
## NASOFARINGE
## 3
## ESOFAGO
## 3
## LARINGE
## 3
## OTRAS GLANDULAS ENDOCRINAS Y ESTRUCTURAS AFINES
## 3
## SITIOS MAL DEFINIDOS Y OTROS
## 3
## PALADAR
## 3
## CAVIDAD NASAL Y OIDO MEDIO
## 3
## BASE LENGUA
## 3
## HIPOFARINGE
## 3
## LABIO
## 3
## OROFARINGE
## 3
## OTROS SITIOS Y LOS MAL DEF. DE LOS ORGANOS DIGESTIVOS
## 3
## SENOS PARANASALES
## 3
## OTROS ORGANOS GENITALES FEMENINOS Y LOS NO ESPECIF.
## 3
## PELVIS RENAL
## 3
## MENINGES
## 3
## MEDULA ESPINAL, NERVIOS CRANEALES Y DE OTRAS PARTES DEL SISTEMA NERVIOSO CENTRAL
## 3
## GLANDULA SUPRARRENAL (ADRENAL)
## 3
## PISO DE LA BOCA
## 3
## TRAQUEA
## 3
## OTROS ORGANOS URINARIOS Y LOS NO ESPECIF.
## 3
## ENCIA
## 3
## SENO PIRIFORME
## 3
## OTROS SITIOS Y LOS MAL DEF. DEL LABIO, CAVIDAD BUCAL Y FARINGE
## 3
## TIMO
## 3
## OTROS SITIOS Y LOS MAL DEF. DEL SIST. RESP. Y LOS ORG. INTRAT.
## 3
## NERVIOS PERIFERICOS Y SISTEMA NERVIOSO AUTONOMO
## 3
## PLACENTA
## 3
## PENE
## 3
## GLANDULA PROSTATICA
## 3
## TESTICULOS
## 3
## OTROS ORGANOS GENITALES MASCULINOS Y LOS NO ESPECIF.
## 3
## URETER
## 3
##
## Within cluster sum of squares by cluster:
## [1] 34.93713 38.82212 55.42256 0.00000 25.53163
## (between_SS / total_SS = 86.0 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault"
fviz_cluster(k5, data = datosClusterIncidencia, ellipse.type = "euclid",repel = TRUE,star.plot = TRUE)Vamos a realizar una tabla que contenga el grupo en el que fue clasificado el cáncer según k = 2 y k = 5.
incidenciaCluster$k2 <- as.factor(k2$cluster)
incidenciaCluster$k5 <- as.factor(k5$cluster)
datatable(incidenciaCluster, class = 'cell-border stripe', options = list(pageLength = 5))Incidencia por Cantón y Provincia
#Lectura de los datos
cantonesIncidencia <- read.table("2014_mujeres_incidencia_canton.txt", header = TRUE, sep = "\t", quote = "\"",
dec = ",", fill = TRUE)
head(cantonesIncidencia)## PROVINCIA.Y.CANTON PROVINCIA N_TOTAL TASA_TOTAL MAMA PIEL
## 1 COSTA RICA TOTAL 6056 256.31 55.87 55.61
## 2 SAN JOSE <NA> 2642 332.62 68.74 73.65
## 3 CENTRAL SAN JOSE 762 454.82 101.47 108.04
## 4 ESCAZU SAN JOSE 91 271.86 77.67 47.80
## 5 DESAMPARADOS SAN JOSE 281 242.78 51.84 56.16
## 6 PURISCAL SAN JOSE 71 402.18 62.31 226.58
## CUELLO.DEL.UTERO TIROIDES ESTOMAGO COLON CUERPO.DEL.UTERO GANGLIOS.LINF.
## 1 29.33 28.40 12.06 11.85 8.93 5.04
## 2 35.13 37.64 14.73 16.24 10.32 8.44
## 3 45.36 40.59 16.12 17.91 17.91 10.15
## 4 17.92 41.82 14.94 20.91 0.00 2.99
## 5 33.70 25.06 10.37 7.78 5.18 5.18
## 6 11.33 11.33 0.00 11.33 0.00 16.99
## OVARIO PULMON OTRAS.LOCALIZAC.
## 1 4.57 4.53 40.12
## 2 6.42 5.29 56.02
## 3 5.97 10.15 81.18
## 4 5.97 5.97 35.85
## 5 4.32 3.46 39.74
## 6 11.33 16.99 33.99
Podemos observar el nombre de los canceres más frecuentes de la siguiente forma.
colnames(cantonesIncidencia[5:15])## [1] "MAMA" "PIEL" "CUELLO.DEL.UTERO" "TIROIDES"
## [5] "ESTOMAGO" "COLON" "CUERPO.DEL.UTERO" "GANGLIOS.LINF."
## [9] "OVARIO" "PULMON" "OTRAS.LOCALIZAC."
Vamos a crear una table interactiva que resuma los datos.
datatable(cantonesIncidencia, options = list(pageLength = 5)) #bugdatatable(cantonesIncidencia, options = list(pageLength = 5))Vamos a graficar la incidencia según la provincia.
#Guardamos los nombres de las provincias en un vector
provincias <- c("SAN JOSE", "ALAJUELA", "HEREDIA", "CARTAGO", "GUANACASTE",
"PUNTARENAS", "LIMON")
#Selecionamos los datos de las provincias
incidenciaProvincia <- cantonesIncidencia[
cantonesIncidencia$PROVINCIA.Y.CANTON %in% provincias,]
#Gráfico de barras
ggplot(incidenciaProvincia, aes(x = reorder(PROVINCIA.Y.CANTON, -TASA_TOTAL) , y = TASA_TOTAL, fill = "")) +
geom_bar(stat="identity", color = "black",
position = "dodge", width = 0.8) +
labs(y = "Incidencia cada 100.000 habitantes",
x = "Provincia",
fill = "Año") + theme_classic() + theme(legend.position = "none")Vamos a generar un heatmap de incidencia según el tipo de cáncer y cantón
#Eliminamos las provincias del set de datos
cantonesIncidencia <- cantonesIncidencia[
!(cantonesIncidencia$PROVINCIA.Y.CANTON %in% provincias),]
#Cambiamos nombres de "Central" al nombre del cantón
cantonesIncidencia$PROVINCIA.Y.CANTON[2] = "SAN JOSE"
cantonesIncidencia$PROVINCIA.Y.CANTON[23] = "ALAJUELA"
cantonesIncidencia$PROVINCIA.Y.CANTON[39] = "CARTAGO"
cantonesIncidencia$PROVINCIA.Y.CANTON[48] = "HEREDIA"
cantonesIncidencia$PROVINCIA.Y.CANTON[71] = "PUNTARENAS"
cantonesIncidencia$PROVINCIA.Y.CANTON[83] = "LIMON"
#Transformamos los datos "a lo largo"
cantonLargo <- pivot_longer(cantonesIncidencia, cols=5:15, names_to = "Localizacion", values_to = "Incidencia")
#Heatmap
p2 <- ggplot(cantonLargo, aes(x= reorder(PROVINCIA.Y.CANTON, -TASA_TOTAL) ,
y= reorder(Localizacion, -Incidencia), fill= Incidencia)) +
geom_tile() + theme(axis.text.x = element_text(angle = 45, hjust = 1, size ="3"),
axis.text.y = element_text(size = "8")) +
paletteer::scale_fill_paletteer_c("viridis::plasma") +
labs(y = "Localización",
x = "Cantón")
#ggplotly(p2)
p2Agrupamiento por cantones
Primero debemos manipular los datos.
#Clustering
#Eliminamos la fila de "Costa Rica"
cantonesCluster<- cantonesIncidencia[-1,]
#Eliminamos los cantones "Desconocido
cantonesCluster <- cantonesCluster[!(cantonesCluster$PROVINCIA.Y.CANTON == "DESCONOCIDO"), ]
#Guardamos esta variable para más tarde
tablaCluster <- cantonesCluster
rownames(cantonesCluster) <- cantonesCluster$PROVINCIA.Y.CANTON
#Eliminamos columnas de PROVINCIA.Y.CANTON, PROVINCIA y N_TOTAL
cantonesCluster <- cantonesCluster[, -c(1:3)]
head(cantonesCluster)## TASA_TOTAL MAMA PIEL CUELLO.DEL.UTERO TIROIDES ESTOMAGO COLON
## SAN JOSE 454.82 101.47 108.04 45.36 40.59 16.12 17.91
## ESCAZU 271.86 77.67 47.80 17.92 41.82 14.94 20.91
## DESAMPARADOS 242.78 51.84 56.16 33.70 25.06 10.37 7.78
## PURISCAL 402.18 62.31 226.58 11.33 11.33 0.00 11.33
## TARRAZU 232.45 58.11 11.62 34.87 34.87 11.62 11.62
## ASERRI 210.86 30.12 66.94 36.82 26.78 3.35 3.35
## CUERPO.DEL.UTERO GANGLIOS.LINF. OVARIO PULMON OTRAS.LOCALIZAC.
## SAN JOSE 17.91 10.15 5.97 10.15 81.18
## ESCAZU 0.00 2.99 5.97 5.97 35.85
## DESAMPARADOS 5.18 5.18 4.32 3.46 39.74
## PURISCAL 0.00 16.99 11.33 16.99 33.99
## TARRAZU 0.00 0.00 0.00 0.00 69.74
## ASERRI 3.35 3.35 3.35 0.00 33.47
Debemos determinar la cantidad de clusters.
#Escalamos los datos
cantonesCluster <- scale(cantonesCluster)
#Realizamos el k-means
#número de clusters, vamos a usar tres índices distintos.
library(factoextra)
fviz_nbclust(cantonesCluster, kmeans, method = "wss")fviz_nbclust(cantonesCluster, kmeans, method = "silhouette")fviz_nbclust(cantonesCluster, kmeans, method = "gap_stat")Debido a que los resultados anteriores no son concluyentes, usamos la regla de la mayoría.
resnumclust<-NbClust(cantonesCluster, distance = "euclidean", min.nc=2, max.nc=10, method = "kmeans", index = "alllong")## *** : The Hubert index is a graphical method of determining the number of clusters.
## In the plot of Hubert index, we seek a significant knee that corresponds to a
## significant increase of the value of the measure i.e the significant peak in Hubert
## index second differences plot.
##
## *** : The D index is a graphical method of determining the number of clusters.
## In the plot of D index, we seek a significant knee (the significant peak in Dindex
## second differences plot) that corresponds to a significant increase of the value of
## the measure.
##
## *******************************************************************
## * Among all indices:
## * 9 proposed 2 as the best number of clusters
## * 5 proposed 3 as the best number of clusters
## * 2 proposed 4 as the best number of clusters
## * 1 proposed 5 as the best number of clusters
## * 1 proposed 6 as the best number of clusters
## * 5 proposed 7 as the best number of clusters
## * 1 proposed 8 as the best number of clusters
## * 1 proposed 9 as the best number of clusters
## * 2 proposed 10 as the best number of clusters
##
## ***** Conclusion *****
##
## * According to the majority rule, the best number of clusters is 2
##
##
## *******************************************************************
fviz_nbclust(resnumclust)## Warning in if (class(best_nc) == "numeric") print(best_nc) else if
## (class(best_nc) == : la condición tiene longitud > 1 y sólo el primer elemento
## será usado
## Warning in if (class(best_nc) == "matrix") .viz_NbClust(x, print.summary, : la
## condición tiene longitud > 1 y sólo el primer elemento será usado
## Warning in if (class(best_nc) == "numeric") print(best_nc) else if
## (class(best_nc) == : la condición tiene longitud > 1 y sólo el primer elemento
## será usado
## Warning in if (class(best_nc) == "matrix") {: la condición tiene longitud > 1 y
## sólo el primer elemento será usado
## Among all indices:
## ===================
## * 2 proposed 0 as the best number of clusters
## * 1 proposed 1 as the best number of clusters
## * 9 proposed 2 as the best number of clusters
## * 5 proposed 3 as the best number of clusters
## * 2 proposed 4 as the best number of clusters
## * 1 proposed 5 as the best number of clusters
## * 1 proposed 6 as the best number of clusters
## * 5 proposed 7 as the best number of clusters
## * 1 proposed 8 as the best number of clusters
## * 1 proposed 9 as the best number of clusters
## * 2 proposed 10 as the best number of clusters
##
## Conclusion
## =========================
## * According to the majority rule, the best number of clusters is 2 .
K-Means (k = 2)
k_2 <- kmeans(cantonesCluster, centers = 2, nstart = 50)
k_2## K-means clustering with 2 clusters of sizes 32, 50
##
## Cluster means:
## TASA_TOTAL MAMA PIEL CUELLO.DEL.UTERO TIROIDES ESTOMAGO
## 1 0.9560680 0.6637530 0.5159222 0.012923247 0.4717257 0.3857901
## 2 -0.6118835 -0.4248019 -0.3301902 -0.008270878 -0.3019045 -0.2469057
## COLON CUERPO.DEL.UTERO GANGLIOS.LINF. OVARIO PULMON
## 1 0.7095223 0.3645739 0.2791550 0.4911820 0.3003294
## 2 -0.4540943 -0.2333273 -0.1786592 -0.3143565 -0.1922108
## OTRAS.LOCALIZAC.
## 1 0.7493901
## 2 -0.4796097
##
## Clustering vector:
## SAN JOSE ESCAZU DESAMPARADOS PURISCAL TARRAZU
## 1 1 2 1 2
## ASERRI MORA GOICOECHEA SANTA ANA ALAJUELITA
## 2 1 1 1 2
## CORONADO ACOSTA TIBAS MORAVIA MONTES DE OCA
## 1 1 1 1 1
## TURRUBARES DOTA CURRIDABAT PEREZ ZELEDON LEON CORTES
## 1 1 1 1 1
## ALAJUELA SAN RAMON GRECIA SAN MATEO ATENAS
## 1 2 1 1 1
## NARANJO PALMARES POAS OROTINA SAN CARLOS
## 2 1 2 1 2
## ALFARO RUIZ VALVERDE VEGA UPALA LOS CHILES GUATUSO
## 2 2 2 2 2
## CARTAGO PARAISO LA UNION JIMENEZ TURRIALBA
## 1 2 2 2 1
## ALVARADO OREAMUNO EL GUARCO HEREDIA BARVA
## 1 2 2 1 2
## SANTO DOMINGO SANTA BARBARA SAN RAFAEL SAN ISIDRO BELEN
## 1 2 2 2 1
## FLORES SAN PABLO SARAPIQUI LIBERIA NICOYA
## 1 2 2 1 2
## SANTA CRUZ BAGACES CARRILLO CAÑAS ABANGARES
## 2 2 2 2 2
## TILARAN NANDAYURE LA CRUZ HOJANCHA PUNTARENAS
## 2 1 2 2 2
## ESPARZA BUENOS AIRES MONTES DE ORO OSA AGUIRRE
## 2 2 1 2 2
## GOLFITO COTO BRUS PARRITA CORREDORES GARABITO
## 2 2 2 2 2
## LIMON POCOCI SIQUIRRES TALAMANCA MATINA
## 2 2 2 2 2
## GUACIMO EXTRANJERO
## 2 2
##
## Within cluster sum of squares by cluster:
## [1] 447.9522 335.1385
## (between_SS / total_SS = 19.4 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault"
fviz_cluster(k_2, data = cantonesCluster, ellipse.type = "euclid",repel = TRUE,star.plot = TRUE)tablaCluster$k_2 <- as.factor(k_2$cluster)
clado2 <- hcut(cantonesCluster, k = 2, stand = TRUE)
fviz_dend(clado2, rect = TRUE, cex = 0.4,
k_colors = c("red","#2E9FDF"))K-Means (k = 7)
k_7 <- kmeans(cantonesCluster, centers = 7, nstart = 50)
k_7## K-means clustering with 7 clusters of sizes 14, 28, 4, 2, 8, 25, 1
##
## Cluster means:
## TASA_TOTAL MAMA PIEL CUELLO.DEL.UTERO TIROIDES ESTOMAGO
## 1 1.3281963 0.9299008 0.18765372 0.2565086 1.27413622 0.8656998
## 2 -1.0040725 -0.7838211 -0.53305328 -0.3115309 -0.34520201 -0.4430995
## 3 0.9770047 -0.4233320 2.54888702 -0.9400571 0.01217390 -1.1960175
## 4 0.5601758 -0.9120284 1.06184510 -0.3599882 -1.38366197 1.0257812
## 5 -0.1762139 -0.1833128 -0.55327148 1.4586893 -0.67012545 -0.4025827
## 6 0.1684001 0.5771412 0.09365901 -0.1754068 0.05164172 0.2974471
## 7 1.6906207 -0.5162612 2.06379810 2.3276037 -1.38366197 -1.1960175
## COLON CUERPO.DEL.UTERO GANGLIOS.LINF. OVARIO PULMON
## 1 1.09557260 0.4129782 0.706366755 0.62926735 0.1583069
## 2 -0.74653735 -0.3969091 -0.002551548 -0.42413174 -0.1000866
## 3 1.45787947 -1.0941545 -0.020404550 -0.05733213 1.3441231
## 4 1.28551989 2.9214716 0.051071678 -0.84586939 2.7424538
## 5 -0.26977505 0.9957282 -0.733143909 -0.10562342 -0.2638646
## 6 0.02108783 -0.2868773 -0.127555955 0.03207071 -0.3010547
## 7 -1.20652367 3.0715417 -0.784166247 5.03023267 -0.6379875
## OTRAS.LOCALIZAC.
## 1 1.19919456
## 2 -0.71941031
## 3 0.08367872
## 4 0.10367046
## 5 0.19213732
## 6 -0.01810780
## 7 1.72830542
##
## Clustering vector:
## SAN JOSE ESCAZU DESAMPARADOS PURISCAL TARRAZU
## 1 6 6 3 6
## ASERRI MORA GOICOECHEA SANTA ANA ALAJUELITA
## 2 1 1 6 6
## CORONADO ACOSTA TIBAS MORAVIA MONTES DE OCA
## 1 1 1 1 1
## TURRUBARES DOTA CURRIDABAT PEREZ ZELEDON LEON CORTES
## 7 5 1 1 1
## ALAJUELA SAN RAMON GRECIA SAN MATEO ATENAS
## 6 6 6 3 1
## NARANJO PALMARES POAS OROTINA SAN CARLOS
## 6 6 3 4 5
## ALFARO RUIZ VALVERDE VEGA UPALA LOS CHILES GUATUSO
## 2 6 2 2 2
## CARTAGO PARAISO LA UNION JIMENEZ TURRIALBA
## 6 2 2 6 6
## ALVARADO OREAMUNO EL GUARCO HEREDIA BARVA
## 1 2 6 6 5
## SANTO DOMINGO SANTA BARBARA SAN RAFAEL SAN ISIDRO BELEN
## 1 5 6 5 6
## FLORES SAN PABLO SARAPIQUI LIBERIA NICOYA
## 6 5 2 6 2
## SANTA CRUZ BAGACES CARRILLO CAÑAS ABANGARES
## 2 2 2 6 2
## TILARAN NANDAYURE LA CRUZ HOJANCHA PUNTARENAS
## 6 4 5 2 6
## ESPARZA BUENOS AIRES MONTES DE ORO OSA AGUIRRE
## 2 2 3 2 2
## GOLFITO COTO BRUS PARRITA CORREDORES GARABITO
## 2 6 2 5 2
## LIMON POCOCI SIQUIRRES TALAMANCA MATINA
## 2 6 2 2 2
## GUACIMO EXTRANJERO
## 2 2
##
## Within cluster sum of squares by cluster:
## [1] 144.13884 150.39273 36.78953 13.57237 54.19552 124.49174 0.00000
## (between_SS / total_SS = 46.1 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault"
fviz_cluster(k_7, data = cantonesCluster, ellipse.type = "euclid",repel = TRUE,star.plot = TRUE)## Too few points to calculate an ellipse
## Too few points to calculate an ellipse
clado7 <- hcut(cantonesCluster, k = 7, stand = TRUE)
fviz_dend(clado7, rect = TRUE, cex = 0.4)Vamos a realizar una tabla que contenga el grupo en el que fue clasificado el cantón según k = 2 y k = 7.
tablaCluster$k_7 <- as.factor(k_7$cluster)
tablaCluster$k_2 <- as.factor(k_2$cluster)
datatable(tablaCluster, class = 'cell-border stripe', options = list(pageLength = 5)) Correlaciones en casos de interés de edad vs. incidencia
Primero se deben manipular los datos.
datosCorrelacion <- datosLargo
#Transformamos datos de rango de edad a númerico
datosCorrelacion$Edad <- gsub(".*-","",datosCorrelacion$Edad)
#Cambiamos string "75+" por 80
datosCorrelacion$Edad[which(datosCorrelacion$Edad == "75+")] = 80
datosCorrelacion$Edad <- as.numeric(datosCorrelacion$Edad)
head(datosCorrelacion)## # A tibble: 6 x 7
## id localizacion n_total incidencia_total year Edad Incidencia
## <chr> <chr> <int> <dbl> <dbl> <dbl> <dbl>
## 1 0 TOTAL 5292 238. 2009 5 12.1
## 2 0 TOTAL 5292 238. 2009 10 10.3
## 3 0 TOTAL 5292 238. 2009 15 14.1
## 4 0 TOTAL 5292 238. 2009 20 22.9
## 5 0 TOTAL 5292 238. 2009 25 44.3
## 6 0 TOTAL 5292 238. 2009 30 85.0
Tiroides
#Seleccionamos los datos
tiroides <- datosCorrelacion[datosCorrelacion$localizacion == "GLANDULA TIROIDES",]
#Valor de correlación
cor(tiroides$Incidencia, tiroides$Edad, method = c("pearson", "kendall", "spearman"))## [1] 0.6561281
#Hay una correlación significativa
cor.test(tiroides$Incidencia, tiroides$Edad,
method = "pearson")##
## Pearson's product-moment correlation
##
## data: tiroides$Incidencia and tiroides$Edad
## t = 8.4296, df = 94, p-value = 3.976e-13
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.5246581 0.7570309
## sample estimates:
## cor
## 0.6561281
Mama
#Seleccionamos los datos
MAMA <- datosCorrelacion[datosCorrelacion$localizacion == "MAMA",]
#Valor de correlación
cor(MAMA$Incidencia, MAMA$Edad, method = c("pearson", "kendall", "spearman"))## [1] 0.9375666
#Hay una correlación significativa
cor.test(MAMA$Incidencia, MAMA$Edad,
method = "pearson")##
## Pearson's product-moment correlation
##
## data: MAMA$Incidencia and MAMA$Edad
## t = 26.135, df = 94, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.9077000 0.9579817
## sample estimates:
## cor
## 0.9375666
Piel
#Seleccionamos los datos
piel <- datosCorrelacion[datosCorrelacion$localizacion == "PIEL",]
#Valor de correlación
cor(piel$Incidencia, piel$Edad, method = c("pearson", "kendall", "spearman"))## [1] 0.7892907
#Hay una correlación significativa
cor.test(piel$Incidencia, piel$Edad,
method = "pearson")##
## Pearson's product-moment correlation
##
## data: piel$Incidencia and piel$Edad
## t = 12.463, df = 94, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.6994939 0.8545510
## sample estimates:
## cor
## 0.7892907
Cuello uterino
#Seleccionamos los datos
uterino <- datosCorrelacion[datosCorrelacion$localizacion == "CUELLO UTERINO",]
#Valor de correlación
cor(uterino$Incidencia, uterino$Edad, method = c("pearson", "kendall", "spearman"))## [1] 0.5092339
#Hay una correlación significativa
cor.test(uterino$Incidencia, uterino$Edad,
method = "pearson")##
## Pearson's product-moment correlation
##
## data: uterino$Incidencia and uterino$Edad
## t = 5.7367, df = 94, p-value = 1.169e-07
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.3438534 0.6439738
## sample estimates:
## cor
## 0.5092339
Gráfico de edad vs. incidencia para los casos de interes en el 2014
cInteres <- rbind(tiroides, MAMA, piel, uterino)
cInteres2014 <- cInteres[cInteres$year == 2014, ]
p3 <- cInteres2014 |> ggplot(aes(x = Edad, y = Incidencia, colour = localizacion)) +
geom_line() + geom_point(size = 2) +
labs(y = "Incidencia cada 100.000 habitantes", x = "Edad", colour = "Localización") + theme_classic()
p3Vemos que cuello uterino & glándula tiroides y mama & piel habian sido clasificados por el K-means (k=5) como grupos diferentes, este gráfico nos confirma que se comportan de forma similar.
Conclusiones
- Para los canceres más frecuentes, desde el 2009 y hasta el 2009, se ha visto una tendencia al alza de los canceres de tiroides y mama.
- Lo anterior se puede deber, al menos en parte, al envejecimiento de la población. Ambos tipos de cáncer se correlación fuertemente con la edad.
- Para el año 2014, la incidencia en mujeres entre los 40 a 65 años ha aumentado en comparación del 2009.
- Es evidente que la incidencia total aumenta según la edad, a partir de los 40 años se superan los 200 casos por cada 100.000 habitantes, y para los 70 se superan los 1000 por cada 100.000 habitantes.
- Para el caso de agrupamiento de los tipos de cáncer según la incidencia por edad, para k = 2, el grupo 1 corresponde a canceres de alta incidencia. Para k = 5, las leucemias fueron agrupadas en grupo por aparte, mientras que los grupos de cuello uterino y tiroides, así como piel y mama fueron agrupados juntos porque la incidencia varia de forma similar con la edad y son de alta incidencia a partir de los 35 años.
- Hay una importante variación para la incidencia entre provincias y entre cantones. Esto se podría deber a factores que estén aumentando la incidencia ciertas regiones (como edad o factores ambientales), pero también se podría deber a un mejor diagnóstico.
- Para el caso de agrupamiento de los cantones según la incidencia de los canceres más frecuentes, para k = 2, el grupo 1 corresponde a cantones con alta incidencia.
- Para un análisis más detallado de los cluster y demás resultados, es necesario un análisis profundo de la bibliografía. También se recomienda incorporar modelos con factores socioeconómicos y otros índices como ruralidad, cantidad de EBAIS por habitante y cantidad de consultas externas.